package com.banzhi.shop.activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import com.banzhi.shop.R;
import com.banzhi.shop.base.BaseActivity;
import com.banzhi.shop.data.CityPartnersData;
import com.banzhi.shop.model.CallBack.CityPartnersCallBack;
import com.banzhi.shop.model.Impl.CityPartnersImpl;
import com.banzhi.shop.utils.LoadingDialogUtils;
import com.banzhi.shop.utils.NoTokenUtils;
import com.banzhi.shop.utils.ToastUtils;
import com.banzhi.shop.utils.Translucent;
import org.json.JSONObject;


//城市合伙人信息
public class CityPartnerActivity extends BaseActivity implements View.OnClickListener, CityPartnersCallBack {
    //总收益
    private TextView mTvTotalRevenue;
    //店长总人数
    private TextView mTvTotalPeople;
    //合伙人总人数
    private TextView mTvTotalPartner;
    private FrameLayout mFlMyShoper;
    private FrameLayout mFlMyPartner;
    private FrameLayout mFlMyRevenue;
    private CityPartnersImpl mCityPartnersModel;
    //待收益
    private TextView mTvWaitRevenue;
    private CityPartnersData mCityPartnersData;
    private ImageView mIvBack;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_city_partner);
        Translucent.setTranslucent(this);

        mCityPartnersModel = new CityPartnersImpl();
        LoadingDialogUtils.showProgress(this, "正在加载,请稍后~");
        mCityPartnersModel.getCityPartnersData(this);
        initView();
        initData();
    }

    private void initView() {
        mTvTotalRevenue = (TextView) findViewById(R.id.tv_total_revenue);
        mTvWaitRevenue = (TextView) findViewById(R.id.tv_wait_revenue);
        mTvTotalPeople = (TextView) findViewById(R.id.tv_total_people);
        mTvTotalPartner = (TextView) findViewById(R.id.tv_total_partner);
        mFlMyShoper = (FrameLayout) findViewById(R.id.fl_my_shoper);
        mFlMyPartner = (FrameLayout) findViewById(R.id.fl_my_partner);
        mFlMyRevenue = (FrameLayout) findViewById(R.id.fl_my_revenue);
        mIvBack = (ImageView) findViewById(R.id.iv_back);
    }

    private void showViews() {
            mTvTotalRevenue.setText(mCityPartnersData.getData().getTotalprofit());
            mTvWaitRevenue.setText(mCityPartnersData.getData().getWaitprofit());
            mTvTotalPeople.setText(mCityPartnersData.getData().getShopowner());
            mTvTotalPartner.setText(mCityPartnersData.getData().getCitypartner());
    }

    private void initData() {
        mFlMyShoper.setOnClickListener(this);
        mFlMyPartner.setOnClickListener(this);
        mFlMyRevenue.setOnClickListener(this);
        mIvBack.setOnClickListener(this);

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.fl_my_shoper:
                //跳转到我的店长
                Intent intent = new Intent(this, MyShoperActivity.class);
                intent.putExtra("sum",mCityPartnersData.getData().getShopowner());
                startActivity(intent);
                break;
            case R.id.fl_my_partner:
                //跳转到我的合伙人
                Intent intent1 = new Intent(this, MyPartnersActivity.class);
                intent1.putExtra("sum2",mCityPartnersData.getData().getCitypartner());
                startActivity(intent1);

                break;
            case R.id.fl_my_revenue:
                //挑转到合伙人收益明细
         //    startActivity(new Intent(this,ShouyiJIluActivity.class));
                startActivity(new Intent(this,PartnerShouYiActivity.class));
                break;
        }

    }
    //获取城市合伙人数据
    @Override
    public void getCityPartnersDataSuccess(Object object) {
        mCityPartnersData = (CityPartnersData) object;
        showViews();
    }
    //获取城市合伙人数据失败
    @Override
    public void getCityPartnersDataError(Object object) {
        JSONObject jsonObject = (JSONObject) object;
        NoTokenUtils.loginOut(this, jsonObject);
        ToastUtils.makeToastShort(jsonObject.optString("msg"));
    }
}
